#pragma once
#include <string>
#include <vector>
#include <map>
#include "SQLCommon.h"
#include "SQLHeader.h"
#include "SQLCheckError.h"
using std::string;

const string OP[9] = {
	"=", "<>", ">", "<", ">=", "<=", "IS NULL", "IS NOT NULL", "LIKE"
};
const string QUERY_TITLE[20] = {
		"CREATE TABLE ", "DROP TABLE ", "INSERT INTO ", "DELETE FROM ", "UPDATE ", "SELECT ",
		"VALUES ", "SET ", "FROM ", "WHERE ",
		"create table ", "drop table ", "insert into ", "delete from ", "update ", "select ",
		" values ", "set ", "from ", "where ",
};	

class SQLParser
{
private:
	vector <string> sqlSeg;
	vector <int> sqlSegType;
	string sqlQuery;
	QueryInfo* queryInfo;

	int Segmentation();
	int QueryCreateTable(); 
	int QueryDropTable();
	int QueryInsertInto();
	int QueryDeleteFrom();
	int QueryUpdate();
	int QuerySelect();

	vector<string> DivideByString(string src, string div);
	vector<ColInfo> GetColumns(string src);
	vector<string> GetTables(string src);
	vector<ConditionInfo> GetConditions(string src, int scope);
	string DeWhiteSpace(string target);
	int FindString(string src, string p);
	
public:
	SQLParser(void);
	~SQLParser(void);
	QueryInfo InitQuery(string sqlQuery);
	QueryInfo FillInfo(QueryInfo);
	void PrintQueryInfo();
};
